import baseURL from "@/common/url"
import axios from "axios"; // 引用axios
const instance = axios.create({
    baseURL: baseURL,
    timeout: 60000,
});

instance.interceptors.request.use(function (config) {
    config.headers.token = window.localStorage.getItem('admin_token')
    config.ContentType = "multipart/form-data"
    return config;
}, function (error) {
    return Promise.reject(error);
});

//get请求
export function get(url, data, headers = {}) {
    return new Promise((resolve, reject) => {
        instance.get(url, data, { headers }).then((response) => {
            resolve(response);
        }).catch((err) => {
            reject(err);
        });
    });
}

//post请求
export function postFile(url, data = {}, headers = {}) {
    return new Promise((resolve, reject) => {
        instance.post(url, data, { headers }).then(
            (response) => {
                resolve(response);
            },
            (err) => {
                reject(err);
            }
        );
    });
}
